package com.xhapi.test;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.xhapi.pojo.entity.ChoiceQuestionsByAi;

import java.util.ArrayList;
import java.util.List;

public class JsonToArrays {
    public static void main(String[] args) {
        String q = """
                                [{
                                    "question":"生成的问题1",
                                    "difficulty":"生成的难度1",
                                    "answer":"生成的答案1",
                                    "analysis":"生成的分析1",
                                    "knowledgePoint":"相关知识点1"
                                },
                                {
                                    "question":"生成的问题2",
                                    "difficulty":"生成的难度2",
                                    "answer":"生成的答案2",
                                    "analysis":"生成的分析2",
                                    "knowledgePoint":"相关知识点2"
                                },
                                {
                                    "question":"生成的问题3",
                                    "difficulty":"生成的难度3",
                                    "answer":"生成的答案3",
                                    "analysis":"生成的分析3",
                                    "knowledgePoint":"相关知识点3"
                                },
                                {
                                    "question":"生成的问题4",
                                    "difficulty":"生成的难度4",
                                    "answer":"生成的答案4",
                                    "analysis":"生成的分析4",
                                    "knowledgePoint":"相关知识点4"
                                },
                                {
                                    "question":"生成的问题5",
                                    "difficulty":"生成的难度5",
                                    "answer":"生成的答案5",
                                    "analysis":"生成的分析5",
                                    "knowledgePoint":"相关知识点5"
                                }]
                """;
        Gson gson=new Gson();
        JsonParser jsonParser=new JsonParser();
        JsonArray jsonArray=jsonParser.parse(q).getAsJsonArray();
        List<ChoiceQuestionsByAi>choiceQuestionsByAiList=new ArrayList<>();
        for (JsonElement jsonElement : jsonArray) {
            ChoiceQuestionsByAi choiceQuestionsByAi=gson.fromJson(jsonElement,ChoiceQuestionsByAi.class);
            choiceQuestionsByAiList.add(choiceQuestionsByAi);
            System.out.println(choiceQuestionsByAi.getQuestion());
        }

    }
}
